<?php
/*
 * @Author: lokei
 * @Date: 2023-06-27 00:06:54
 * @LastEditors: lokei
 * @LastEditTime: 2023-06-27 00:10:03
 * @Description: 
 */
namespace App\Http\Controllers\Store\Mode;

use App\Common\Tools\ResultTool;
use App\Http\Controllers\Controller;
use App\Models\Store\StoreModel;
use Illuminate\Http\Request;

class AppController extends Controller {
    public function get(Request $request) {
        $store = StoreModel::where('id', '=', $request->input('id'))->first();
        if(is_null($store)) {
            $store = new StoreModel();
            $store->id = $request->input('id');
            $store->save();
            $store = StoreModel::where('id', '=', $request->input('id'))->first();
        }
        $res = ResultTool::success();
        $res['data'] = [
            'app_mode' => $store->app_mode,
            'index_mode' => $store->index_mode
        ];
        return $res;
    }

    public function set(Request $request) {
        $store = StoreModel::where('id', '=', $request->input('id'))->first();
        if(is_null($store)) {
            $store = new StoreModel();
            $store->id = $request->input('id');
            $store->save();
            $store = StoreModel::where('id', '=', $request->input('id'))->first();
        }
        $store->app_mode = $request->input('app_mode');
        $store->index_mode = $request->input('index_mode');
        $store->save();
        return ResultTool::success();
    }
}